-
-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix multiple byte tests #31
Fix multiple byte tests #31
Conversation
Had to upgrade prettier to make CI work again ;-) |
Pull Request Test Coverage Report for Build 836689211
💛 - Coveralls |
Pull Request Test Coverage Report for Build 1130221971
💛 - Coveralls |
@epoberezkin could you please review ? Kind regards, |
prettier indeed made some change that changed the required formatting - annoying, I've been bitten by it too. There are no changes in regexes, they are just on the next line, correct?
Some quirk... Maybe some other method should be used, or is it just how it is? |
Correct, all other changes apart from byte are performed by prettier and just put them on the next line. I haven't touched them.
It is the recommended way according to StackOverflow ;-) Kind regards, |
@epoberezkin are you ok with this fix ? |
@epoberezkin can you please review again ? Kind regards, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, to reduce noise, I suggest fixing prettier version at 2.0.5 and I would commit style changes separately
function byte(str: string): boolean { | ||
const BYTE = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm | ||
return BYTE.test(str) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think rather than defining regex locally it would be better to reset the index on regex after the call and have regex itself defined once in the scope of this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To keep the code concise I propose to do it like this:
const BYTE = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm
function byte(str: string): boolean {
BYTE.lastIndex = 0
return BYTE.test(str)
}
Ok ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes - thank you
I tried downgrading my local prettier to 2.0.5 but that results in other problems:
So can I propose that you upgrade prettier on master after which I will add my few lines of code? Kind regards, |
yes - thank you - done! |
@seriousme actually, the diff is now smaller, so the only thing that's left is taking regex out of the function - will you do it? Thank you |
Like I said, most of the changes were due to prettier ;-) Please review again. Kind regards, |
Byte is defined in the openapi specification as Base64
Base64 data can span multiple lines, hence the
/gm
.The challenge with
/gm
is that it won't reset thelastIndex
of the RegExp.So when the next call tries to use the RegExp it will fail because
lastIndex
has not been reset.This PR fixes that by defining the RegExp locally.
Added a test that proves it works ok now, that same test failed without the fix.
Kind regards,
Hans